package com.naiterui.ehp.bp.support.exception;

import static com.naiterui.ehp.bp.support.message.MessageContext.message;

import cn.hutool.core.util.StrUtil;

import org.springframework.util.StringUtils;

public class PublicService {

    /**
     * 获取结果VO
     */
    public static ResponseVO<Void> returnResponseVO(int code) {
        return new ResponseVO<>(code);
    }

    /**
     * 获取结果VO
     */
    public static <T> ResponseVO<T> returnResponseVO(T data) {
        return PublicService.returnResponseVO(BaseExceptionCodes.SUCCESS, data);
    }

    /**
     * 获取结果VO
     */
    public static <T> ResponseVO<T> returnResponseVO(int code, T data) {
        return PublicService.returnResponseVO(code, "", data);
    }

    public static <T> ResponseVO<T> returnResponseVO(int code, String msg, T data) {
        if (StrUtil.isBlank(msg)) {
            msg = message(code);
        }
        return new ResponseVO<>(code, msg, data);
    }

    /**
     * 判断参数是否为null
     *
     * @param params
     *
     * @return
     */
    public static boolean paramsHasNull(Object... params) {
        if (params != null && params.length != 0) {
            for (Object str : params) {
                if (StringUtils.isEmpty(str)) {
                    return true;
                }
            }
            return false;
        }
        return false;
    }


}
